﻿@model OrderMasterModel

@{
    ViewBag.Title = "修改价格";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@{
    var viewModel = Model ?? new OrderMasterModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
    Dictionary<string, string> labelDicTypeName = ReleaseBiz.GetLabelTypeNameDic();
}
<form id="S_Form" action="@Url.Action("DoEditPrice", "OrderMaster")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2" style="width:50%">
                <h5>
                    销售订单详情
                </h5>
                <input type="hidden" value="@viewModel.view_Order.order_id" name="order_id" />
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">订单号</td>
            <td>
                @viewModel.view_Order.order_NO
            </td>

            <td class="tableleft">下单用户</td>
            <td>
                <div>手机号：@viewModel.view_Order.account_mobile</div>
                <div>会员名称：@viewModel.view_Order.member_name</div>
                <div>代购编号：@viewModel.view_Order.replace_buyer_NO</div>
            </td>
        </tr>
        <tr>
            <td class="tableleft">订单金额</td>
            <td>
                @if (viewModel.view_Order.order_source == 12)
                {
                    <div id="show_total_money" style="display:block">
                        <info>  @viewModel.view_Order.total_money </info>
                        @if (viewModel.view_Order.order_status == (int)OrderStatus.WaitPay)
                        {
                            <a href="javascript:void()" onclick="$('#show_total_money').hide(); $('#xiugai_total_money').show();">修改</a>
                        }
                    </div>
                    <div id="xiugai_total_money" style="display:none">
                        <input type="text" name="total_money" id="total_money" value="@viewModel.view_Order.total_money" />
                        <input type="button" id="tijiao_total_money" value="提交修改" />&nbsp;<a href="javascript:void()" onclick="$('#xiugai_total_money').hide(); $('#show_total_money').show();">取消</a>
                    </div>
                    <info>竞价订单请直接修改订单金额</info>
                }
                else
                {
                    <info>  @viewModel.view_Order.total_money </info>
                }
            </td>
            <td class="tableleft">订单状态</td>
            <td>
                @(MyEnumHelper.GetEnumItemDescription<OrderStatus>(viewModel.view_Order.order_status.Value))
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">下单时间</td>
            <td>@viewModel.view_Order.create_time.ToString(1)</td>

            <td width="10%" class="tableleft">支付信息</td>
            <td>
                <div>
                    支付方式：@(MyEnumHelper.GetEnumItemDescription<PayType>(viewModel.view_Order.pay_type.Value))
                </div>
                @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.Paid)
                {
                    <div class="green">已支付 支付时间：@viewModel.view_Order.pay_succ_time.ToString(1)</div>

                    if (viewModel.view_Order.pay_type.Value == (int)PayType.UnderLine)
                    {
                        Html.RenderPartial(Url.Content("~/Views/Common/ImgsOne.cshtml"), viewModel.view_Order);
                    }
                }
                @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.NotPay)
                {
                    <span class="red">
                        未支付
                        @if (viewModel.view_Order.order_status.Value == (int)OrderStatus.Cancel)
                        {
                            <span>支付已关闭</span>
                        }
                        else if (viewModel.view_Order.order_status.Value == (int)OrderStatus.WaitPay)
                        {
                            if (viewModel.view_Order.pay_end_time.HasValue)
                            {
                                <span>支付关闭时间：@viewModel.view_Order.pay_end_time.ToString(1)</span>
                            }
                        }
                    </span>
                }
            </td>
        </tr>
        <tr>
            <td class="tableleft">发货状态<em></em></td>
            <td>
                @{
                    switch (viewModel.view_Order.is_send.Value)
                    {
                        case (int)IsSend.NotSend:
                            <div class="red">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(viewModel.view_Order.is_send.Value))
                            </div>
                            break;
                        case (int)IsSend.Sended:
                            @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<IsSend>(viewModel.view_Order.is_send.Value)) 发货时间：@viewModel.view_Order.send_time.ToString(1)</div>
                            break;
                    }
                }
            </td>
            <td class="tableleft">发票信息<em></em></td>
            <td>
                @switch (viewModel.view_Order.is_invoice.Value)
                {
                    case 0:
                        @:<div>不需要发票</div>
                        break;
                    case 1:
                        if (viewModel.aDZ_OrderInvoiceRel == null)
                        {
                            <div class="red">发票资料还未上传</div>
                        }
                        else
                        {
                            <div>
                                <div class="thumb-item-wrap">
                                    <a href="javacript:void(0);" class="img-wrap">
                                        <img class="thumb-img" src="@ImageFileBiz.GetImg(viewModel.aDZ_OrderInvoiceRel.invoice_img, "small")" style="width: 100px;margin:auto;">
                                    </a>
                                </div>
                            </div>

                            if (viewModel.aDZ_OrderInvoiceRel.is_ready == 1)
                            {
                                <div class="green">发票已开 开票时间：@viewModel.aDZ_OrderInvoiceRel.invoice_date.ToString(1)</div>
                            }
                        }
                        break;
                }
            </td>
        </tr>
        <tr>
            <td colspan="4" style="width:50%">
                <h5>
                    商品信息
                </h5>
            </td>
        </tr>
        <tr>
            <td colspan="4" style="width:100%">
                <table class="table table-bordered table-hover definewidth m10">
                    <thead>
                        <tr>
                            <th style="width:70px">图片</th>
                            <th>料号</th>
                            <th>品牌</th>
                            <th>分类</th>
                            <th>供应商</th>
                            <th>板块</th>
                            <th>DC号</th>
                            <th>库存价格</th>
                            <th>数量</th>
                            <th>改后数量</th>
                            <th>单位</th>
                            <th>单价</th>
                            <th>改后单价</th>
                            <th>商品金额</th>
                            <th>改后金额</th>
                            <th>币种</th>
                        </tr>
                    </thead>
                    @if (viewModel.orderGoods != null && viewModel.orderGoods.Count != 0)
                    {
                        int index = 0;
                        foreach (var orderGoods in viewModel.orderGoods)
                        {
                            var m = orderGoods.views_Goods;
                            var goodsdetail = orderGoods.aDZ_OrderDetails;
                            index++;
                <tr class="@HtmlPagerHelper.TrClass(index)">
                    <td>
                        @{
                            var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id);
                            foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                            {
                                <a href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                            }
                        }
                    </td>
                    <td>@m.MPN</td>
                    <td>@m.brand_name</td>
                    <td>@m.category_name</td>
                    <td>@m.supplier_name</td>
                    <td>
                        <div>@labelDicTypeName[m.label_type.ToString()]</div>
                    </td>
                    <td>@m.DCN</td>
                    <td>@m.price</td>
                    <td>@goodsdetail.amount</td>
                    <td><input type="text" name="aDZ_OrderDetails[@(index-1)].amount" id="aDZ_OrderDetails_amount_@(index-1)" value="@goodsdetail.amount.Value" onblur="onHandlerChange(@(index-1))" onchange="onHandlerChange(@(index-1))" /></td>
                    <td>@m.goods_unit</td>

                        <td>@(goodsdetail.sell_price.ToString("f5"))</td>
                        <td><input type="text" id="aDZ_OrderDetails_price_@(index-1)" value="@(goodsdetail.sell_price.ToString("f5"))" onblur="onHandlerChange(@(index-1))" onchange="onHandlerChange(@(index-1))" /></td>

                    <td>@goodsdetail.total_money.Value.ToString("f2")</td>
                    <td>
                        <input type="hidden" name="aDZ_OrderDetails[@(index-1)].goods_id" value="@m.goods_id" />
                        <input type="text" name="aDZ_OrderDetails[@(index-1)].total_money" id="aDZ_OrderDetails_total_money_@(index-1)" value="@goodsdetail.total_money.Value.ToString("f2")" onblur="onHandlerChangeTotal(@(index-1))" onchange="onHandlerChangeTotal(@(index-1))" />
                    </td>
                    <td>
                        @switch (m.currency_type)
                        {
                            case 0:
                                @:<div class="">人民币</div>
                                break;
                            case 1:
                                @:<div class="red">美金</div>
                                break;
                        }
                    </td>
                </tr>
                        }
                    }
                </table>
            </td>
        </tr>

        <tr>
            <td class="tableleft">修改原因<em></em></td>
            <td><textarea id="reason" name="reason" style="width:80%;" maxlength="2500" placeholder="填写修改原因" cols="4"></textarea></td>
        </tr>
        <tr>
            <td colspan="4" style="width:50%">
                @if (viewModel.view_Order.order_source != 12)
                {
                    <button type="button" class="btn btn-primary" onclick="editprice()">提交修改</button>
                }
                <button type="button" class="btn btn-success" name="backid" id="backid">返回</button>
            </td>
        </tr>

    </table>
</form>
<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };

    function editprice() {
        var order_id = "@viewModel.view_Order.order_id";

        BUI.Message.Show({
            title: '提示',
            msg: '确定要修改订单数量价格吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      $("#S_Form").ajaxSubmit(function (result) {
                          ShowActionResult(result, function () { self.location = document.referrer; });
                      });
                  }
              },
                cancelButton

            ]
        });
    }
    function onHandlerChange(index) {
        var newamont = $("#aDZ_OrderDetails_amount_"+index).val();
        var newprice = $("#aDZ_OrderDetails_price_"+index).val();
        $("#aDZ_OrderDetails_total_money_"+index).val(newamont*newprice);
    }
    function onHandlerChangeTotal(index) {
        var total = $("#aDZ_OrderDetails_total_money_"+index).val();
        var newamont = $("#aDZ_OrderDetails_amount_"+index).val();
        $("#aDZ_OrderDetails_price_"+index).val(total/newamont);
    }

    $("#tijiao_total_money").click(function () {
        BUI.Message.Show({
            title: '提示',
            msg: '确认要修改订单价格吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("modifytotalmoney", "OrderMaster")";
                      parameter = {
                          id: @viewModel.view_Order.order_id,
                          newtotalmoney: $("#total_money").val()
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    });
</script>
